﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;


namespace logwiz
{
    

    public partial class Form1 : Form
    {
        string sCompName; // to store the name of the local computer 
        string sTrgtCompName; //to run the perfmon log on. Incase the user is trying to run the logs remotely. Need to compare the name later.
        int sz; // total number of perf counters on the server 
        string[] chkboxname = new string[500];
        string cmd1, cmd2, cmd3; // variable to set the logman command
        string cmd4 = "start logwiz";
        public void addcounters()  // for adding the counters dynamically to the form once we load it.

        {
            int topPosition = 10;
            PerformanceCounterCategory[] perfCounters = PerformanceCounterCategory.GetCategories();
            sz = perfCounters.Length;
            string[] perfcountername = new string[sz];
            string[] chkboxname = new string[sz];
            for (int i = 0; i < perfCounters.Length; i++)
            {
                perfcountername[i] = perfCounters[i].CategoryName.ToString();
            }
            int j = 0;

            foreach (string pc in perfcountername)
            {
                CheckBox checkBox = new CheckBox();
                checkBox.Top = topPosition;
                checkBox.Left = 10;
                checkBox.Text = pc;
                topPosition += 20;
                checkBox.Name = chkboxname[j];
                flowLayoutPanel1.Controls.Add(checkBox);
                j++;

            }


        }
        public void createcmd() // for creating the logman command
        {
            listBox1.Items.Clear();
            cmd1 = cmd2 = null;
            foreach (Control c in flowLayoutPanel1.Controls)
            {
                if (c is CheckBox)
                {
                    CheckState x = ((CheckBox)c).CheckState; // Do whatever you want to do with CheckedState ( Value Of Check box )
                    if (((CheckBox)c).Checked == true)
                    {
                        listBox1.Items.Add(c.Text);
                     //   cmd1 = "\"\\" + c.Text + "(*)\\*"\\";
                      cmd1 = "\"\\"+ c.Text +"(*)\\*\" ";
                        cmd2 = cmd2 + cmd1;

                        //"\LogicalDisk(*)\*"
                    }
                }

            }
           // cmd2 = cmd2 + cmd1;
            //textBox8.Text = cmd2;
            cmd3 = "create counter logwiz -c " + cmd2 + " -f bincirc -max 300 -si 00:00:05  -v mmddhhmm";
            textBox8.Text = cmd3;
        }
        public Form1()
        {
            InitializeComponent();
            PerformanceCounterCategory[] perfCounters = PerformanceCounterCategory.GetCategories();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int a = tabControl1.SelectedIndex;
            a++;
            tabControl1.SelectedIndex = a;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int a = tabControl1.SelectedIndex;
            a--;
            tabControl1.SelectedIndex = a;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.Text = System.Environment.MachineName.ToString();
            sCompName = textBox1.Text;
            textBox2.Text = System.Environment.MachineName.ToString();
            sTrgtCompName = textBox2.Text;
            addcounters();

        }

        private void button4_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowDialog();
            textBox5.Text = folderBrowserDialog1.SelectedPath;

        }

        private void button5_Click(object sender, EventArgs e)
        {

            
            //int l = listBox1.Items.Count;
            //int i = 0;

            //textBox8.Text = listBox1.Items.IndexOf(1).ToString();


            //do
            //{
            //    textBox8.Text = "\\" + listBox1.Items.IndexOf(i).ToString(); // +"(*)\\*\"";
            //    //cmd1 ;
            //} while(i <= l);


            //lmnt6 = "create counter perf_log -c \"\\Processor(*)\\*\" \"\\Memory\\*\" \"\\PhysicalDisk(*)\\*\" \"Process(*)\\*\" \"\\System\\*\" -f bincirc -max 300 -si 00:00:05  -v mmddhhmm";
            //lms = "start perf_log";



        }

        private void button7_Click(object sender, EventArgs e)
        {
            createcmd();
            System.Diagnostics.Process.Start(@"logman", cmd3);
            

        }

        private void button3_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start(@"logman", cmd4);
            Application.Exit();
        }

    //    private void button6_Click(object sender, EventArgs e)
        //{
        //    listBox1.Items.Clear();
        //    cmd1 = cmd2 = null;
        //    foreach (Control c in flowLayoutPanel1.Controls)
        //    {
        //        if (c is CheckBox)
        //        {
        //            CheckState x =((CheckBox)c).CheckState; // Do whatever you want to do with CheckedState ( Value Of Check box )
        //            if (((CheckBox)c).Checked == true)
        //            {
        //                listBox1.Items.Add(c.Text);
        //                cmd1 = "\"\\" + c.Text + "(*)\\*\" \"";
        //                cmd2 = cmd2 + cmd1;
                            
        //            }
        //        }
                
        //    }
        //  //  cmd2 = cmd2 + cmd1;
        //    cmd3 = "create counter logwiz -c " + cmd2 + "-f bincirc -max 300 -si 00:00:05  -v mmddhhmm";
        //    textBox8.Text = cmd3;

        

       

        
    }
}
